<template>
    <div>
        <a href="http://localhost:8081/" style="font-size: 20px">首页</a>
        <div style="display: flex;justify-content: center;margin-top: 150px">
            <el-card style="width: 400px">
                <div slot="header" class="clearfix">
                    <span>登录</span>
                </div>
                <table>
                    <tr>
                        <td>用户名</td>
                        <td>
                            <el-input v-model="loginForm.tradername" placeholder="请输入经销商用户名"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>密码</td>
                        <td>
                            <el-input type="password" v-model="loginForm.password" placeholder="请输入密码" @keydown.enter.native="doLogin"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <!-- 占两行-->
                        <td colspan="2">
                            <!-- 点击事件的两种不同的写法v-on:click和 @click-->
                            <!--<el-button style="width: 300px" type="primary" v-on:click="doLogin">登录</el-button>-->
                            <el-button style="width: 300px" type="primary" @click="doLogin">登录</el-button>
                        </td>
                    </tr>
                </table>
            </el-card>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return{
                loginForm:{
                    tradername:'',
                    password:'',
                    //为了登录方便，可以直接在这里写好用户名和密码的值
                }
            }
        },
        methods:{
            doLogin(){
                var that=this;
                var tradername=this.loginForm.tradername;
                var password=this.loginForm.password;
                axios.get('http://localhost:8080/ocp/login/check?tradername='+tradername+'&password='+password).then(function (resp) {
                    console.log(resp);
                    if(resp.data.message==='success'){
                        that.$cookie.set('tradername',tradername);
                        that.$message('登录成功！欢迎您，'+tradername);
                        that.$router.push({
                            path: '/TraderIndex'
                        })
                    } else {
                        alert('账号或密码不对，请重新登录！');
                        window.location.reload();
                    }
                })
                }
        }
    }
</script>
<style>

</style>

